package com.fmblzf.library.group;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

/**
 * Created by Administrator on 2015/10/20.
 */
public class RelativeSpecialBack extends RelativeLayout {
    public RelativeSpecialBack(Context context) {
        this(context, null, 0);
    }

    public RelativeSpecialBack(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RelativeSpecialBack(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initWidget();
    }

    /**
     * 初始化控件
     */
    private void initWidget() {
        backPaint = new Paint();
        backPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        backPaint.setColor(Color.parseColor("#e2faa2"));
        backPaint.setAntiAlias(true);
    }

    //起点X坐标
    private int startX = 20;
    //倾斜的宽度
    private int width = 20;
    //画刷
    private Paint backPaint;
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Path path = new Path();
        path.moveTo(startX,getHeight()/2);
        path.lineTo(startX + width, 0);
        path.lineTo(getMeasuredWidth(), 0);
        path.lineTo(getMeasuredWidth(), getMeasuredHeight());
        path.lineTo(startX+width,getMeasuredHeight());
        path.close();
        canvas.drawPath(path,backPaint);
    }
}
